package com.example.child_protection.service.impl;

import com.example.child_protection.dao.AssessDao;
import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.AssessInsertRequestDTO;
import com.example.child_protection.dto.request.update.AssessUpdateRequestDTO;
import com.example.child_protection.enums.ServiceActionEnums;
import com.example.child_protection.model.AssessModel;
import com.example.child_protection.service.AssessManageService;
import com.example.child_protection.service.base.MyBaseService;
import com.example.child_protection.service.base.MyServiceExecutor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 高危管理service实现层
 * @date 2018-11-2
 * @author Biz
 */
@Component
public class AssessManageServiceImpl extends MyBaseService implements AssessManageService {

    @Autowired
    public AssessDao assessDao;

    /**
     * 添加
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO insert(AssessInsertRequestDTO requestDTO){
        return this.service(ServiceActionEnums.ASSESS_INSERT,requestDTO, BaseResponseDTO.class, new MyServiceExecutor<AssessInsertRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(AssessInsertRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                AssessModel model = new AssessModel();
                BeanUtils.copyProperties(requestDTO,model);
                assessDao.insert(model);
                res.setId(model.getId());
                res.successfully();
                return res;
            }
        });
    }

    /**
     * 修改
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO update(AssessUpdateRequestDTO requestDTO){
        return this.service(ServiceActionEnums.ASSESS_UPDATE,requestDTO, BaseResponseDTO.class, new MyServiceExecutor<AssessUpdateRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(AssessUpdateRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                AssessModel model = new AssessModel();
                BeanUtils.copyProperties(requestDTO,model);
                assessDao.updateSelective(model);
                res.setId(model.getId());
                res.successfully();
                return res;
            }
        });
    }

    /**
     * 删除
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO){
        return this.service (ServiceActionEnums.ASSESS_DELETE, requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SimpleIdRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SimpleIdRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                AssessModel model = new AssessModel();
                BeanUtils.copyProperties(requestDTO,model);
                assessDao.deleteForLogic(model);
                res.setId(requestDTO.getId());
                res.successfully();
                return res;
            }
        });
    }

}
